'''
@author Michael J Bommarito II
@date Jul 14, 2010
'''

import igraph

class graphSequence(object):
    '''
    Sequence containing the graphs in the order in which they are to be rendered.
    '''
    
    def __init__(self):
        '''
        Default constructor.
        '''
        
        # Sequence of graph objects
        self.graphs = []
        
        # Labels corresponding to each graph object
        self.labels = []
        
    def __len__(self):
        '''
        Overload the length operator to return
        the size of the graph sequence.
        '''
        return len(self.graphs)
    
    def addGraph(self, graph, label = None):
        '''
        Add a single graph element to the sequence.
        '''
        if not isinstance(graph, igraph.Graph):
            raise Exception("GraphMovie::addGraph: graph is not an igraph.Graph object.")
        
        if graph.vcount() == 0:
            raise Exception("GraphMovie::addGraph: graph has 0 vertices.")
        
        self.graphs.append(graph)
        
        if label:
            self.labels.append(label)
        else:
            self.labels.append(str(len(self.graphs)))